<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="会议名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入会议名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" prop="id" />
      <el-table-column label="会议名称" prop="name" />
      <el-table-column label="报名人数" prop="signNum" />
      <el-table-column label="开始时间" prop="startTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" prop="endTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.parentId != 0"
            size="mini"
            type="text"
            @click="handleEdit(scope.row)"
          >编辑</el-button>
          <el-button
            v-if="scope.row.parentId != 0"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleRowDelete(scope.row)"
          >删除</el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleChart" icon="el-icon-key">会议主页</el-dropdown-item>
              <el-dropdown-item command="handleAttendeeManagement" icon="el-icon-key">参会人员管理</el-dropdown-item>
              <el-dropdown-item command="handleMeetingSchedule" icon="el-icon-key">会议环节</el-dropdown-item>
              <el-dropdown-item command="handleSpeechTopic" icon="el-icon-key">演讲主题</el-dropdown-item>
              <el-dropdown-item command="handleVenue" icon="el-icon-key">会场管理</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { listMeet, delMeet } from "@/api/meetingManagement/meet";
import { VueCropper } from "vue-cropper"
import { getToken } from "@/utils/auth";

export default {
  name: "Activity",
  dicts: ['sys_normal_disable'],
  components: { VueCropper },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lastName: undefined,
        firstName: undefined,
        mobile: undefined
      },
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      // 表单参数
      form: {},
      fileList: [],
      fileList2: [],
      uploadImgUrl: process.env.VUE_APP_BASE_API + '/common/upload', // 上传的图片服务器地址
      // 表单校验
      rules: {
        lastName: [
          { required: true, message: "姓不能为空", trigger: "blur" }
        ],
        firstName: [
          { required: true, message: "名不能为空", trigger: "blur" }
        ],
        mobile: [
          { required: true, message: "手机号不能为空", trigger: "blur"},
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "请输入正确的手机号码格式",
            trigger: "blur"
          }
        ]
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true
      listMeet(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.roleList = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push("/meetingManagement/meetingAdd/")
    },
    // 图表按钮操作
    handleChart(row) {
      const id = row.id
      this.$router.push("/meetingManagement/meetingHome/user/" + id)
    },
    // 编辑按钮操作
    handleEdit(row) {
      const id = row.id
      this.$router.push("/meetingManagement/meetingEdit/" + id)
    },
    handleRowDelete(row) {
      this.$modal.confirm('是否确认删除会议id为"' + row.id + '"的数据项？').then(function() {
        return delMeet(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    handleRemove() {
      this.form.photoUrl = null
      this.fileList = []
    },
    handleAttendeeManagement(row) {
      const id = row.id
      this.$router.push("/registryManagement/attendeeManagement/" + id)
    },
    handleMeetingSchedule(row) {
      const id = row.id
      this.$router.push("/scheduleManagement/meetingSchedule/" + id)
    },
    // 演讲主题按钮操作
    handleSpeechTopic(row) {
      const id = row.id
      this.$router.push("/scheduleManagement/speechTopic/" + id)
    },
    // 会场管理按钮操作
    handleVenue(row) {
      const id = row.id
      this.$router.push("/venueManagement/" + id)
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleAttendeeManagement":
          this.handleAttendeeManagement(row)
          break
        case "handleChart":
          this.handleChart(row)
          break
        case "handleMeetingSchedule":
          this.handleMeetingSchedule(row)
          break
        case "handleSpeechTopic":
          this.handleSpeechTopic(row)
          break
        case "handleVenue":
          this.handleVenue(row)
          break
        default:
          break
      }
    },
  }
}

</script>
<style scoped lang="scss">

</style>
